<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>获取子组件中的数据</title>
</head>

<body>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <div id="Application">
        <child ref="hello"></child>
        <button type="button" @click="getHello">获取子组件中的值</button>
    </div>
    <script>
        const App = Vue.createApp({
            setup() {
                const hello = Vue.ref()//获取子组件
                const getHello = () => {
                    console.log("拿到了子组件的信息：", hello.value.msg)
                }
                return {
                    hello,
                    getHello
                }
            },
        });

        //子组件
        const childBlock = {
            setup() {
                const msg = Vue.ref("Hello Worlld")
                return {
                    msg
                }

            },

            template: '<h1>{{msg}}</h1>'
        }
        App.component("child", childBlock);

        //挂载
        App.mount("#Application");
    </script>
</body>

</html>